<?php
namespace app\common\validate;
use app\common\validate\Base;
class SystemAdmin extends Base
{
    protected $rule = [
        'username'  => 'require|unique:system_admin,username',
        'nickname'  => 'require',
        'password'  => 'require',
        'mobile'    => 'require|length:11|unique:system_admin,mobile|checkPhone',
        'roles'     => 'require'
    ];
    protected $message = [
        'username.require'     => '账号不能为空',
        'username.unique'      => '账号重复',
        'nickname.require'     => '昵称不能为空',
        'password.require'     => '密码不能为空',
        'password.min'         => '密码不能少于6位',
        'mobile.require'       => '手机号不能为空',
        'mobile.length'        => '手机号为11位',
        'mobile.unique'        => '手机号重复',
        'roles.require'        => '角色不能为空',
    ];
    protected $scene = [
        'add'  =>  [
            'username',
            'nickname',
            'password'=>"require|min:6|checkPass:add",
            'mobile',
            'roles'
        ],
        'edit' => [
            'username',
            'nickname',
            'password'=>"checkPass:edit",
            'mobile',
            'roles'
        ],
    ];
    // 自定义验证规则
    protected function checkPass($value,$rule,$data)
    {
        if($rule === 'edit' && !$value){
            return true;
        }
        if(!checkPwd($value)){
            return '6-16位字符（英文/数字/!@#$%&~）三种组合';
        }
        return true;
    }
    
}
